package cn.yunhe.controller;

import cn.yunhe.entity.Car;
import cn.yunhe.service.ICarService;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/after/SearchCarServlet")
public class SearchCarServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String keyword = request.getParameter("searchs");
        ICarService carService = new ICarService();
        List<Car> keywodList = carService.searchCar(keyword);

        JSONArray jsonArray = new JSONArray();
        jsonArray.addAll(keywodList);
        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print(jsonArray);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
